home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 580 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: gate.net!pslfl2-14
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with stringcopy
  5. Date: 7 Jan 1996 09:44:52 GMT
  6. Organization: CyberGate, Inc.
  7. Message-ID: <4co4mk$1pqi@news.gate.net>
  8. References: <4clguu$9fs@eagle.novo.dk> <yewvimppjz5.fsf@hyll.idt.unit.no> <4cmafq$bm5@clarknet.clark.net>
  9. NNTP-Posting-Host: pslfl2-14.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4cmafq$bm5@clarknet.clark.net>,
  13.    eamick@clark.net (Eric Amick) wrote:
  14. >Amund Tveit (amundt@pvv.unit.no) wrote:
  15. >>[Morten Brun]
  16. >>
  17. >>|   How do i do a partial stringcopy i.e. copy from a specific position in
  18. >>|   a string and a certain numbers of bytes. I am looking for a function
  19. >>|   like target = Stringcopy(source, startpos, length)
  20. >>
  21. >>You can try something like this :
  22. >>char *Stringcopy(char *source, int startpos, size_t length)
  23. >>{
  24. >>    char tmpstring[SIZEBIGENOUGH];
  25. >>    strncpy((char *)(source+startpos),tmpstring,length);
  26. >>    return tmpstring;
  27. >>}
  28. >
  29. >This won't work as written; the first two arguments to strncpy() are 
  30. >reversed.  The cast is also unnecessary.
  31. >
  32.  
  33. Seems like it's getting closer. Why have a separate function?
  34.  
  35.     strncpy(destination,&source[startpos],max_length);
  36.  
  37. Bill
  38.  
  39. "Whatcha got on?...Your mind?"
  40.